package com.hiwhitley.leetcode.easy;

/**
 * Created by hiwhitley on 17-1-16.
 */
public class RepeatedSubstringPattern_459 {
    public boolean repeatedSubstringPattern(String str) {
        if (str == null || str.equals("")) {
            return false;
        }

        int len = str.length();
        for (int i = len / 2; i >= 1; i--) {
            if (len % i == 0) {
                int m = len / i;
                String subS = str.substring(0, i);
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j < m; j++) {
                    sb.append(subS);
                }
                if (sb.toString().equals(str)) return true;
            }

        }
        return false;
    }
}
